<?php

if (!defined('BASEPATH'))
    exit('No direct script access allowed');

/**
 * @author TUNAFISHIE
 */
class openinghours extends CI_Controller{
    
    function __construct() {
        parent::__construct();
        $this->load->model('openinghours_model');
    }
/*
|--------------------------------------------------------------------------
| getTermOpeningHours (@author : Justina Lee)
|--------------------------------------------------------------------------
|
| This function returns the parsed term opening hours results as JSON and call the 
| function to wrap the response in the requested callback. 
|
*/    
    public function getTermOpeningHours(){        
        $xmlOpeningHoursUrl = $this->config->item('openingHours_xml');
        $xmlSpecialOccasionUrl = $this->config->item('specialOccasion_xml');
        
        $output = $this->openinghours_model->parseTermXml($xmlOpeningHoursUrl, $xmlSpecialOccasionUrl, 0);
        $this->retJsonP($output);
    }
    
/*
|--------------------------------------------------------------------------
| getVBOpeningHours (@author : Justina Lee)
|--------------------------------------------------------------------------
|
| This function returns the parsed vacation/break opening hours results as 
| JSON and call the function to wrap the response in the requested callback. 
|
*/    
    public function getVBOpeningHours(){        
        $xmlOpeningHoursUrl = $this->config->item('openingHours_xml');
        $xmlSpecialOccasionUrl = $this->config->item('specialOccasion_xml');
        
        $output = $this->openinghours_model->parseTermXml($xmlOpeningHoursUrl, $xmlSpecialOccasionUrl, 1);
        $this->retJsonP($output);
    }
   
/*
|--------------------------------------------------------------------------
| retJsonP (@author : Justina Lee)
|--------------------------------------------------------------------------
|
| This function wraps the response in the requested callback. 
|
*/
    function retJsonP($output) {
        $callback = $_REQUEST['callback'];

        if ($callback) {
            header('Content-Type: text/javascript');
            echo $callback . '(' . json_encode($output) . ');';
        } else {
            header('Content-Type: application/x-json');
            echo json_encode($output);
        }
    }
}

?>
